package org.apache.http.entity.mime;

import org.apache.http.a.a;
import org.apache.http.entity.mime.content.ContentBody;

public class b {
    private final String a;
    private final c b = new c();
    private final ContentBody c;

    public b(String str, ContentBody contentBody) {
        a.a((Object) str, "Name");
        a.a((Object) contentBody, "Body");
        this.a = str;
        this.c = contentBody;
        a(contentBody);
        b(contentBody);
        c(contentBody);
    }

    public String a() {
        return this.a;
    }

    public void a(String str, String str2) {
        a.a((Object) str, "Field name");
        this.b.a(new i(str, str2));
    }

    protected void a(ContentBody contentBody) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("form-data; name=\"");
        stringBuilder.append(a());
        stringBuilder.append("\"");
        if (contentBody.getFilename() != null) {
            stringBuilder.append("; filename=\"");
            stringBuilder.append(contentBody.getFilename());
            stringBuilder.append("\"");
        }
        a("Content-Disposition", stringBuilder.toString());
    }

    public ContentBody b() {
        return this.c;
    }

    protected void b(ContentBody contentBody) {
        org.apache.http.entity.b a = contentBody instanceof org.apache.http.entity.mime.content.a ? ((org.apache.http.entity.mime.content.a) contentBody).a() : null;
        if (a != null) {
            a("Content-Type", a.toString());
            return;
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(contentBody.getMimeType());
        if (contentBody.getCharset() != null) {
            stringBuilder.append("; charset=");
            stringBuilder.append(contentBody.getCharset());
        }
        a("Content-Type", stringBuilder.toString());
    }

    public c c() {
        return this.b;
    }

    protected void c(ContentBody contentBody) {
        a("Content-Transfer-Encoding", contentBody.getTransferEncoding());
    }
}
